package com.ghh.encrypto.security;

import java.nio.charset.Charset;

import org.apache.commons.codec.binary.Base64;

public class Base64PasswordEncoder implements PasswordEncryption {

	@Override
	public String encrypt(String plainText) throws Exception {
		if (CommonUtilities.isEmpty(plainText)) {
			return plainText;
		}
		byte[] b = Base64.encodeBase64(plainText.getBytes(Charset.forName("UTF-8")));
		return new String(b, Charset.forName("UTF-8"));
	}

	@Override
	public String decrypt(String encryptText) throws Exception {
		if (CommonUtilities.isEmpty(encryptText)) {
			return encryptText;
		}
		byte[] b = Base64.decodeBase64(encryptText);
		return new String(b, Charset.forName("UTF-8"));
	}
}
